<%--
  Created by IntelliJ IDEA.
  User: Albert Lee
  Date: 2020/5/26
  Time: 16:26
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <title>新建日记</title>
    <script type="text/javascript">
        function validate(){
            var id = document.forms[0].id.value;
            var name = document.forms[0].name.value;// 0为id号。
            var title = document.forms[0].title.value;
            var comment = document.forms[0].comment.value;
            if(id <= 0){
                alert("ID号不能为空，请输入ID号！");
                return false;
            }else if(name.length <= 0){
                alert("类型不能为空，请输入类型！");
                return false;
            } else if(title.length <= 0){
                alert("标题不能为空，请输入标题！");
                return false;
            } else if(comment.length <= 0){
                alert("内容不能为空，请输入内容！");
                return false;
            } else{
                return true;
            }
        }
    </script>
</head>
<link rel="stylesheet" href="css/header.css">


<body background="resourse/bg.jpg">
<%//判断是否登录
    String userid=(String)session.getAttribute("userid");
//    System.out.print("Session userID="+userid);
    if (userid!=null) {
%>

<div id="header"><!--页头-->
    <spana>&emsp;巴以小记</spana>
    <br>
    <spanb>&emsp;&emsp;<%=(String)session.getAttribute("userid")%> 在线中..</spanb>
    <ul>
        <li></li>
        <li><h2 class="main" ><a class="btna" href="main.jsp">主页</a></h2></li>
        <li><h2 class="work"><a class="btna" href="addInfo.jsp">发贴</a></h2></li>
        <li><h2 class="new"><a class="btna" href="showInfo.jsp" >看贴</a></h2></li>
        <li><h2 class="comment"><a class="btna" href="showInfo.jsp" >搜索</a></h2></li>
    </ul>
</div>
<br>


<%
    long time = System.currentTimeMillis() / 1000;
    String ID = String.valueOf(time);
%>

<h3>发新帖</h3><hr>
<center>
    <form action="infoinsert.jsp" method="post" onSubmit="return validate()">
        <table cellSpacing=2 >
            <tr>
                <th colspan="2" align="center"><h3 align="center">标题：<input type="text" name="title" title="标题不能为空"  style="height:30px; width:850px; font-size:30px;"/></h3></th>
            </tr>
            <tr>
                <td align="center">编号：<input type="text" name="id"  value="<%=ID%>" title="编号自动生成" readonly="readonly"></input></td>
                <td align="center">类型：<input type="text" name="name"  title="类型不能为空"></input></td>
            </tr>
            <tr>
                <td align="center"  colspan="2"> <textarea name="comment" rows="20" cols="90" style="font-size:20px" title="内容不能为空"></textarea></td>
            </tr>
            <tr><td align="center"  colspan="2"><input type="submit" value="提交"/></td></tr>
        </table>
    </form>
    <a href="showInfo.jsp">查看所有帖子</a>
</center>


<%
    } else {
      out.print("<script>alert('未成功登录！');" +
       "window.location='http://localhost:8080/index.html';</script>");
    }
%>


</body>
</html>
